package eu.jpereira.trainings.designpatterns.creational.builder.json;

import eu.jpereira.trainings.designpatterns.creational.builder.model.ReportBody;
import eu.jpereira.trainings.designpatterns.creational.builder.ReportBulider;

public class JSONBulider implements ReportBulider {

	private JSONReportBody reportBody;
	private boolean start = true;
	
	public JSONBulider() {
		
		reportBody = new JSONReportBody();
	}
	
	
	
	
	
public ReportBulider setCustomerName(String customerName) {
		
		reportBody.addContent("sale:{customer:{");
		reportBody.addContent("name:\"");
		reportBody.addContent(customerName);
		reportBody.addContent("\"");
		return this;
	}

	public ReportBulider setCustomerPhone(String phoneNumber) {
		
		reportBody.addContent(",phone:\"");
		reportBody.addContent(phoneNumber);
		reportBody.addContent("\"}");
		return this;
	}

	public ReportBulider end() {
		
		if (!start) {
		
			reportBody.addContent("]}");
		}
		
		return this;
	}

	public ReportBulider addItem(String name, int quantity, double price) {
		if (start) {
			reportBody.addContent(",items:[");
			
		}
		if (!start) {reportBody.addContent(",");  }
		if (start ) start = false;
		reportBody.addContent("{name:\"");
		reportBody.addContent(name);
		reportBody.addContent("\",quantity:");
		reportBody.addContent(String.valueOf(quantity));
		reportBody.addContent(",price:");
		reportBody.addContent(String.valueOf(price));
		reportBody.addContent("}");
		
		return this;
	}

	
	
	public ReportBody getReportBody() {
		
		return reportBody;
	}
}
